package bcc.java8.chap02.exe01;

import bcc.java8.chap02.exe01.Apple;
import java.util.ArrayList;
import java.util.List;

/**
 * 缺点：有重复代码
 * @author bcc
 * @Description:
 * @date 2019-09-17 22:24
 */
public class FilteringApplesOldWay {

    /**
     * 选出绿色的苹果
     * @param inventory
     * @return
     */
    public static List<Apple> filterGreenApples(List<Apple> inventory){
        List<Apple> result = new ArrayList<>();
        for(Apple apple: inventory){
            if("green".equals(apple.getColor())){
                result.add(apple);
            }
        }
        return result;
    }

    /**
     * 选出超过150克的苹果
     * @param inventory
     * @return
     */
    public static List<Apple> filterHeavyApples(List<Apple> inventory){
        List<Apple> result = new ArrayList<>();
        for(Apple apple: inventory){
            if("green".equals(apple.getColor())){
                result.add(apple);
            }
        }
        return result;
    }
}
